<?php
// 翻页需要文章的总数和当前的页码
$articleAmount = $this->articleAmount;
$rowCount = Zend_Registry::get('config')->page->number;
$author = $this->author;
$date = $this->date;

if ($articleAmount > $rowCount) {
    ?>
<div class="pagination">
	<div class="number-paginate">
		<span class='number-title'> </span>
        <?php
    $page = $this->page;
    $pageLeft = (int) (Zend_Registry::get('config')->page->button / 2);
    $pageRight = Zend_Registry::get('config')->page->button - $pageLeft - 1;
    $pageBottom = $page - $pageLeft;
    $pageTop = $page + $pageRight;
    if ($articleAmount % $rowCount == 0) {
        $pageNum = $articleAmount / $rowCount;
    } else {
        $pageNum = (int) ($articleAmount / $rowCount) + 1;
    }
    if ($pageBottom < 1) {
        $offset = 1 - $pageBottom;
        $pageTop += $offset;
        $pageBottom = 1;
    }
    if ($pageTop > $pageNum) {
        $offset = $pageTop - $pageNum;
        $pageBottom -= $offset;
        if ($pageBottom < 1) {
            $pageBottom = 1;
        }
        $pageTop = $pageNum;
    }
    if ($page == 1) {
        ?>
        <span class='number-prev number-current'>«</span> <span
			class='number-page number-current'>1</span>
        <?php
    } else {
        ?>
        <a
			href="<?php echo APPLICATION_URL; ?>/<?php echo $this->controller; ?>/index/page/<?php
        echo $page - 1; 
        echo $this->decoratePageUrl($author, $date);
        ?>"
			class='number-prev'>«</a> <a
			href='<?php echo APPLICATION_URL; ?>/<?php echo $this->controller; ?>/index/page/1<?php echo $this->decoratePageUrl($author, $date); ?>'
			class='number-page'>1</a>
        <?php
    }
    ?>
        
        <?php
    if ($pageBottom > 1 + 1) {
        ?>
        <span class='number-gap'><?php
        echo Zend_Registry::get('config')->page->gap;
        ?></span>
        <?php
    }
    ?>
        
        <?php
    for ($i = $pageBottom; $i <= $pageTop; $i ++) {
        if ($i == 1 || $i == $pageNum) {
            continue;
        }
        if ($page == $i) {
            ?>
        <span class='number-page number-current'><?php
            echo $i;
            ?></span>
        <?php
        } else {
            ?>
        <a
			href='<?php echo APPLICATION_URL; ?>/<?php echo $this->controller; ?>/index/page/<?php
            echo $i;
            echo $this->decoratePageUrl($author, $date);
            ?>'
			class='number-page'><?php
            echo $i;
            ?></a>
        <?php
        }
    }
    ?>
        
        <?php
    if ($pageTop < $pageNum - 1) {
        ?>
        <span class='number-gap'><?php
        echo Zend_Registry::get('config')->page->gap;
        ?></span>
        <?php
    }
    ?>
        
        <?php
    if ($page == $pageNum) {
        ?>
        <span class='number-page number-current'><?php
        echo $pageNum;
        ?></span> <span class='number-next number-current'>»</span>
        <?php
    } else {
        ?>
        <a
			href='<?php echo APPLICATION_URL; ?>/<?php echo $this->controller; ?>/index/page/<?php
        echo $pageNum;
        echo $this->decoratePageUrl($author, $date); ?>'
			class='number-page'><?php
        echo $pageNum?></a> <a
			href='<?php echo APPLICATION_URL; ?>/<?php echo $this->controller; ?>/index/page/<?php
        echo $page + 1;
        echo $this->decoratePageUrl($author, $date); ?>'
			class='number-next'>»</a>
        <?php
    }
    ?>
    </div>
</div>
<?php
}
?>